//背景白天转黑夜
import { Behaviour } from "../engine/Behaviour";
import { getGameObjectById } from "../engine";
import { TextRenderer } from "../engine/TextRenderer";
import { BitmapRenderer } from "../engine/BitmapRenderer";
import { Clock } from "./Clock";
import { Bill_OK_Click } from "./Bill_OK_Click";

export class changeToANewDay extends Behaviour{

    public DTMaa = 0
    changeFlag = false

    onStart(){
        //隔一段时间自动跳转
       this.changeScene()  
    }

    changeScene(){
        //console.log("进入changescene了！！！！！！！！！")
        this.changeFlag = getGameObjectById('UI_Button_Nextday').getBehaviour(Bill_OK_Click).changeFlag          
        
       setTimeout(() => {
        if(this.changeFlag){
            this.DTMaa ++
            console.log("DTMaa:" + this.DTMaa)
            if(this.DTMaa === 2){
                //开启钟表
                getGameObjectById('UI_time_text').getBehaviour(Clock).start = true
                //跳转场景
                this.engine.scenenumber=3
                //重置一下时间（不想等几秒。。。立马执行）
                getGameObjectById('schoolgatebackground_day').getBehaviour(BitmapRenderer).source =  "./assets/images/background_school_day.png"
                getGameObjectById('UI_time_text').getBehaviour(TextRenderer).text = "16：00"
                getGameObjectById('UI_time_sun2').getBehaviour(BitmapRenderer).source =  "./assets/images/UI_time_0sun.png"
                this.DTMaa = 0;
                getGameObjectById('UI_Button_Nextday').getBehaviour(Bill_OK_Click).changeFlag = false
                console.log("跳转了~~~~~~~~~~~~~")
            }
        }else{
            return 123
        }   
        this.changeScene()
       }, 2000);

    }
}